<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script>
    //Array对象定义
    /*var arr = new Array(1, 2, 3);
    var arr1 = ["a", "b", "c"];
    arr1[0] = "aa"; // a --> aa
    alert(arr1);  //aa, b, c*/

    /*//元素访问
    var arr2 = ["a", "b", 1, 2];
    arr2[10] = true;
    alert(arr2);  //a,b,1,2,,,,,,,true
    alert(arr2[10]);  //true
    alert(arr2[9]);  //undefined
    alert(arr2[11]);  //undefined*/

    /*//属性
    var arr3 = [1, 3, 5, 7, 9];
    for (let i = 0; i < arr3.length; i++) {
      alert(arr3[i]); //  1 3 5 7 9
    }
    for (const number of arr3) {
      alert(number); //  1 3 5 7 9
    }*/

    /*//函数（方法）
    var arr4 = [1, 2, 3];
    arr4.push(4); //将元素4添加到数组末尾
    alert(arr4);  //1, 2, 3, 4
    arr4.splice(1, 2);  //从 1 索引位置开始连续删除 2 个元素
    alert(arr4);  //1, 4*/

    //定义方法获取数组元素的最大值，并返回
    function getMax(arr) {
        let max = arr[0];
        for (let i = 0; i < arr.length; i++) {
            if (max < arr[i]) {
                max = arr[i];
            }
        }
        return max;
    }
    const ARR = [1, 3, 5, 7, 2, 4, 6];
    alert(getMax(ARR)); //7
</script>
</body>
</html>